package towerDefense;

/**
 * The superclass to all towers. This class provides the necessary methods 
 * to begin building/selling all types of towers. <br /><br />
 * 
 * Subclasses may be deprecated in the future to allow for a XML defined 
 * version to be implemented.  The reasoning behind this possible move is 
 * to allow for slight changes to be loaded on the fly without the need 
 * to (re)build a new subclass. 
 * 
 * @author Guillermo Mendez-Kestler
 *
 */
public class T_Tower extends T_Object implements I_Tower {
	/**
	 * Current POWER LEVEL the tower is at. 
	 */
	private int TOWER_LEVEL;

	/**
	 * The radius of the Tower range
	 */
	private double TOWER_RANGE;

	/**
	 * Current cost to upgrade/build the tower. Begins at 0.   
	 */
	private int BUILD_COST = 0;
	
	/**
	 * Cost to upgrade the tower. This amount gets added onto the amount
	 */
	private int UPGRADE_COST = 0;

	/**
	 * Builds a tower at LEVEL 1
	 * 
	 * @param type The type of tower built. 
	 */
	public T_Tower(int type) {
		super(type);
		World.addT_Tower(this);
		TOWER_LEVEL=1;
	}//*/

	/**
	 * Builds a tower at LEVEL 1 at the specified coordinates. 
	 * 
	 * @param xCoord X Coordinate the tower will be built at. 
	 * @param yCoord Y Coordinate the tower will be built at. 
	 * @param size Size
	 * @param type Type of tower built. 
	 */
	public T_Tower(double xCoord, double yCoord, double size, int type) {
		super(xCoord, yCoord, size, type);
		World.addT_Tower(this);
		TOWER_LEVEL=1;
		//BUILD_COST+=INITIAL_BUILD_COST+UPGRADE_COST;
		setBuildCost(getBuildCost() + (DEFAULT_INITIAL_BUILD_COST+DEFAULT_UPGRADE_COST)); // REMOVE DEFAULT_
	} //*/

	/**
	 * Set the initial amount to build the tower. 
	 * 
	 * @param buildCost The cost to set the initial build cost. 
	 */
	public void setBuildCost(int buildCost) {
		BUILD_COST = buildCost;
	}

	/**
	 * The initial cost to upgrade the tower. 
	 * 
	 * @return The initial cost to build the tower. 
	 */
	public int getBuildCost() {
		return BUILD_COST;
	}

	/**
	 * Set the cost to upgrade the tower. This is the default amount 
	 * that gets added to the total cost to upgrade the tower.
	 * 
	 * @param upgradeCost Set the upgrade cost. 
	 */
	public void setUpgradeCost(int upgradeCost) {
		UPGRADE_COST = upgradeCost;
	}

	/**
	 * Return the cost to upgrade the tower. This is the default amount 
	 * that gets added to the total cost to upgrade the tower. 
	 * 
	 * @return The upgrade cost. 
	 */
	public int getUpgradeCost() {
		return UPGRADE_COST;
	}

	/* (non-Javadoc)
	 * @see myTowerDefense.T_Tower#getTowerLevel()
	 */
	public int getTowerLevel() {
		return TOWER_LEVEL;
	}

	/* (non-Javadoc)
	 * @see myTowerDefense.T_Tower#getTowerRange()
	 */
	public double getTowerRange() {
		return TOWER_RANGE;
	}

	/* (non-Javadoc)
	 * @see myTowerDefense.T_Tower#costToUpgrade()
	 */
	public int costToUpgrade() {
		return getBuildCost();
	}

	/* (non-Javadoc)
	 * @see myTowerDefense.T_Tower#upgradeTower()
	 */
	public boolean upgradeTower() {
		if (TOWER_LEVEL == MAX_TOWER_LEVEL){
			return false;
		}
		else {
			TOWER_LEVEL++;
			if (TOWER_LEVEL==MAX_TOWER_LEVEL)
				BUILD_COST = -1;
			else 
				setBuildCost(getBuildCost() + DEFAULT_UPGRADE_COST); // REMOVE DEFAULT_
			return true;
		}
	}

}
